@extends('layouts.admin')

@section('title')
    预设组
@endsection

@section('content-header')
    <h1>预设组<small>当前系统中所有可用的预设组。</small></h1>
    <ol class="breadcrumb">
        <li><a href="{{ route('admin.index') }}">管理</a></li>
        <li class="active">预设组</li>
    </ol>
@endsection

@section('content')
    <div class="row">
        <div class="col-xs-12">
            <div class="alert alert-danger">
                预设是Pterodactyl面板的强大功能，允许极大的灵活性和配置。请注意，虽然功能强大，但错误地修改预设很容易导致您的服务器出现问题。除非您完全确定自己在做什么，否则请避免编辑我们的默认预设——那些由<code>support@pterodactyl.io</code>提供的预设。
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">已配置的预设组</h3>
                    <div class="box-tools">
                        <a href="#" class="btn btn-sm btn-success" data-toggle="modal"
                            data-target="#importServiceOptionModal" role="button"><i class="fa fa-upload"></i> 导入预设</a>
                        <a href="{{ route('admin.nests.new') }}" class="btn btn-primary btn-sm">创建新的</a>
                    </div>
                </div>
                <div class="box-body table-responsive no-padding">
                    <table class="table table-hover">
                        <tr>
                            <th>ID</th>
                            <th>名称</th>
                            <th>描述</th>
                            <th class="text-center">预设数量</th>
                            <th class="text-center">服务器数量</th>
                        </tr>
                        @foreach($nests as $nest)
                            <tr>
                                <td class="middle"><code>{{ $nest->id }}</code></td>
                                <td class="middle"><a href="{{ route('admin.nests.view', $nest->id) }}" data-toggle="tooltip"
                                        data-placement="right" title="{{ $nest->author }}">{{ $nest->name }}</a></td>
                                <td class="col-xs-6 middle">{{ $nest->description }}</td>
                                <td class="text-center middle">{{ $nest->eggs_count }}</td>
                                <td class="text-center middle">{{ $nest->servers_count }}</td>
                            </tr>
                        @endforeach
                    </table>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" tabindex="-1" role="dialog" id="importServiceOptionModal">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">导入预设</h4>
                </div>
                <form action="{{ route('admin.nests.egg.import') }}" enctype="multipart/form-data" method="POST">
                    <div class="modal-body">
                        <div class="form-group">
                            <label class="control-label" for="pImportFile">预设文件 <span class="field-required"></span></label>
                            <div>
                                <input id="pImportFile" type="file" name="import_file" class="form-control"
                                    accept="application/json" />
                                <p class="small text-muted">选择您希望导入的新预设的<code>.json</code>文件。</p>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label" for="pImportToNest">关联预设组 <span
                                    class="field-required"></span></label>
                            <div>
                                <select id="pImportToNest" name="import_to_nest">
                                    @foreach($nests as $nest)
                                        <option value="{{ $nest->id }}">{{ $nest->name }} &lt;{{ $nest->author }}&gt;</option>
                                    @endforeach
                                </select>
                                <p class="small text-muted">从下拉列表中选择此预设将关联的预设组。如果您希望将其关联到新的预设组，需要先创建该预设组。</p>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        {{ csrf_field() }}
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-primary">导入</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection

@section('footer-scripts')
    @parent
    <script>
        $(document).ready(function () {
            $('#pImportToNest').select2();
        });
    </script>
@endsection